package com.demo.dao;

import com.demo.common.model.Flightrecord;
import com.jfinal.kit.Kv;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.SqlPara;

import java.util.List;

public class FlightrecordDao {

    private Flightrecord dao = new Flightrecord().dao();

    public Page<Flightrecord> paginate(int pageNumber, int pageSize) {
        return dao.paginate(pageNumber, pageSize, "select *", "from flightrecord order by id asc");
    }

    public Page<Flightrecord> paginate(int pageNumber, int pageSize, Kv cond) {
        SqlPara sqlPara = dao.getSqlPara("searchFlightrecord",cond);
        return dao.paginate(pageNumber, pageSize, sqlPara);
    }

    public Flightrecord findById(int id) {
        return dao.findById(id);
    }

    public void deleteById(int id) {
        dao.deleteById(id);
    }

    public List<Flightrecord> findAll() {
        return dao.findAll();
    }

    public int findDistancesByUserId(int userid){
        String sql="select IFNULL(sum(distance),0) distances from flightrecord where userid="+userid;
        return Db.queryInt(sql);
    }
}
